import re

text  = 'foo = 23 + 42 * 10'

NAME = r'(?P<NAME>[a-zA-Z_0-9])'

master_pat = re.compile(NAME)

master_pat.scanner(text)